package no.endelighelg.app;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;

public class EHHttpGet extends HttpGet {
	public EHHttpGet(String string) {
		super(string);
	}

	public JSONArray getJSONArray() {
		JSONArray json = null;
		
		DefaultHttpClient httpclient = new DefaultHttpClient();
		this.addHeader("User-Agent", "endelighelg/1.0 android");
		
		try {
			HttpResponse resp = httpclient.execute(this);
			BasicResponseHandler responseHandler = new BasicResponseHandler();
			String content = responseHandler.handleResponse(resp);
			
			try {
				json = new JSONArray(content);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		catch (ClientProtocolException e) {
			e.printStackTrace();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		
		return json;
	}
}

